import opera

filename = '/home/yin/workplace/python_workplace/excel/plink-0.xlsx'


def test_get_sheets():
    sheets = opera.get_sheets(filename)
    print(sheets)
    return sheets


def func1(data):
    return data['当前状态'].startswith('已关闭')


def func2(data):
    return data['责任人'].startswith('尹')


def edit1(data):
    data['test'] = 'demo'
    return data


def edit2(data):
    data['DTS'] = 'link ' + data['DTS']
    return data


def update_edit1(line, data):
    ans = {}
    for k in line.keys():
        ans[k] = line[k] + 'demo'
    return ans


def test_get_sheet_headers():
    data = opera.search(filename, 'Sheet1')
    # data = opera.search(filename, 'Sheet1', filter_list=[func1, func2], edit_list=[edit1, edit2, 'tst'])
    print(data)
    opera.edit(filename, 'Sheet1', [], [update_edit1])

    data.append({
        'DTS': 'DTS00006',
        '责任人': 'test',
        '当前': 'None',
    })
    opera.insert_lines(filename, 'Sheet1', data=data, mode='overwrite')
    data = opera.search(filename, 'Sheet1')
    print(data)
